<?php
class NotFoundHandler
{
    public static function handle(CExceptionEvent $event)
    {
        $exception = $event->exception;
        if (get_class($exception) == "CHttpException" &&
            $exception->statusCode === 404
        ) {
            $pathParts = explode('/', Yii::app()->
                getRequest()->getRequestUri());
            $pathPart = array_pop($pathParts);
            $criteria = new CDbCriteria();
            $criteria->addSearchCondition('nama', $pathPart,true,'or');
            $criteria->addSearchCondition('name_', $pathPart,true,'or');
            $criteria->addSearchCondition('isi', $pathPart,true,'or');
            $criteria->addSearchCondition('content', $pathPart,true,'or');
            //$criteria->limit = 5;
            $models = Berita::model()->findAll($criteria);

            $controller = new CController(null);
            $controller->renderPartial('//error/404', array(
                'models' => $models,
            ));
            $event->handled = true;
        }
    }
}